package com.tiny.climber;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import com.tiny.core.game.states.GameState;
import com.tiny.core.game.states.StateBasedGame;
import com.tiny.core.input.KeyboardManager;
import com.tiny.core.resources.ImageManager;
import com.tiny.gui.utils.CenteredText;

public class Menu implements GameState {

    private BufferedImage title;
    private CenteredText enter;
    private CenteredText escape;

    @Override
    public void onLoad(StateBasedGame game) {
        Font font = new Font("Verdana", Font.BOLD, 25);
        ImageManager images = new ImageManager();
        title = images.loadImage("img/title.png");

        enter = new CenteredText(800, 50, 0, title.getHeight() + 10, "Press 'Enter' to start", font, Color.WHITE);
        enter.prepare();

        escape = new CenteredText(800, 50, 0, enter.getY() + 5, "Press 'Escape' to exit", font, Color.WHITE);
        escape.prepare();
    }

    @Override
    public void onRender(Graphics2D g, StateBasedGame game) {
        g.drawImage(title, null, 0, 0);
        enter.render(g);
        escape.render(g);
    }

    @Override
    public void onUnload(StateBasedGame game) {

    }

    @Override
    public void onUpdate(int currentTick, StateBasedGame game) {
        if (KeyboardManager.getInstance().isPressed(KeyEvent.VK_ESCAPE)) {
            game.terminate();
        }

        if (KeyboardManager.getInstance().isPressed(KeyEvent.VK_ENTER)) {
            game.enterState(Main.CLIMB_GAME);
        }
    }
}
